package com.shaunstone.web.sports.dal.model;

import java.io.Serializable;

import javax.persistence.*;

/**
 * The persistent class for the person_team_mapping database table.
 * 
 */
@Entity
@Table(name = "person_team_mapping")
@NamedQuery(name = "PersonTeamMapping.findAll", query = "SELECT p FROM PersonTeamMapping p")
public class PersonTeamMapping implements Serializable {
	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private PersonTeamMappingPK id;

	// TODO add position

	private String role;

	// bi-directional many-to-one association to Person
	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "person_id", insertable = false, updatable = false)
	private Person person;

	// bi-directional many-to-one association to Team

	@ManyToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "team_id", insertable = false, updatable = false)
	private Team team;

	public PersonTeamMapping() {
	}

	public PersonTeamMappingPK getId() {
		return this.id;
	}

	public void setId(PersonTeamMappingPK id) {
		this.id = id;
	}

	public String getRole() {
		return this.role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public Person getPerson() {
		return this.person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public Team getTeam() {
		return this.team;
	}

	public void setTeam(Team team) {
		this.team = team;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((person == null) ? 0 : person.hashCode());
		result = prime * result + ((role == null) ? 0 : role.hashCode());
		result = prime * result + ((team == null) ? 0 : team.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PersonTeamMapping other = (PersonTeamMapping) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (person == null) {
			if (other.person != null)
				return false;
		} else if (!person.equals(other.person))
			return false;
		if (role == null) {
			if (other.role != null)
				return false;
		} else if (!role.equals(other.role))
			return false;
		if (team == null) {
			if (other.team != null)
				return false;
		} else if (!team.equals(other.team))
			return false;
		return true;
	}

}